package demo;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Slf4j
public class FixResponseEncoding {
    public static void main(String[] args) {
        try {
            Connection.Response response = Jsoup.connect("https://sales.tungee.com/api/...")
                    .header("Accept-Encoding", "gzip, deflate") // 控制压缩方式
//                    .responseCharset("UTF-8") // 强制编码
                    .ignoreContentType(true)
                    .execute();

            // 诊断响应头
           log.info("Headers: " + response.headers());

            // 原始字节解码
            byte[] bytes = response.bodyAsBytes();
            String body = new String(bytes, StandardCharsets.UTF_8);
           log.info("Decoded content: " + body);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}